﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Cephei
{
    public class CellBuilder : ICell_Factory 
    {
        private static Lazy<ICell_Factory> _fac = new Lazy<ICell_Factory> (LoadInstance);

        private static ICell_Factory LoadInstance ()
        {
            Assembly.Load (new AssemblyName ("Cephei.Cell.dll"));
            Type FactoryType = Type.GetType ("Cephei.Cell_Factory");
            return (ICell_Factory) Activator.CreateInstance (FactoryType);
        }

        public static ICell_Factory Instance
        {
            get
            {
                return _fac.Value;
            }
        }

        public Generic.ICell<T> Create<T> ()
        {
            return _fac.Value.Create<T> ();
        }

        public Generic.ICell<T> Create<T> (IFormula<T> formula)
        {
            return _fac.Value.Create<T> (formula);
        }

        public Generic.ICell<T> Create<T> (Microsoft.FSharp.Control.FSharpAsync<T> async)
        {
            return _fac.Value.Create<T> (async);
        }

        public Generic.ICell<T> Create<T> (Microsoft.FSharp.Core.FSharpFunc<Microsoft.FSharp.Core.Unit, T> fastfunc)
        {
            return _fac.Value.Create<T> (fastfunc);
        }

        public Generic.ICell<T> Create<T> (T t)
        {
            return _fac.Value.Create<T> (t);
        }

        public Generic.ICell<T> Create<T> (IModel model, string mnmonic)
        {
            return _fac.Value.Create<T> (model, mnmonic);
        }

        public Generic.ICell<T> Create<T> (T t, IModel model, string mnmonic)
        {
            return _fac.Value.Create<T> (t, model, mnmonic);
        }

        public ICell Create (IModel model, string mnmonic)
        {
            return _fac.Value.Create (model, mnmonic);
        }

        public Generic.ICell<T> Create<T> (Microsoft.FSharp.Control.FSharpAsync<T> async, IModel model, string mnmonic)
        {
            return _fac.Value.Create<T> (async, model, mnmonic);
        }

        public Generic.ICell<T> Create<T> (Microsoft.FSharp.Core.FSharpFunc<Microsoft.FSharp.Core.Unit, T> fastfunc, IModel model, string mnmonic)
        {
            return _fac.Value.Create<T> (fastfunc, model, mnmonic);
        }
    }
}
